package com.jx.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jx.dao.FindFuncsDao;
import com.jx.daoimpl.FindFuncsDaoImpl;
import com.jx.model.Func;
import com.jx.service.FindFuncsService;
import com.jx.servicrimpl.FindFuncsServiceImpl;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class FindAllFuncsController extends HttpServlet{
	FindFuncsService ffs=new FindFuncsServiceImpl();
	FindFuncsDao ffd=new FindFuncsDaoImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		//获取所有的功能
		List<Func> allFuncs =ffd.findFuncsDao(0, ffd.findTotalFuncs());
		
		JSONArray funcsarr=new JSONArray();
		JSONObject jfuncs=new JSONObject();
		for (Func func : allFuncs) {
			jfuncs.put("func", func);
			funcsarr.add(jfuncs);
		}
		PrintWriter pw=resp.getWriter();
		pw.write(String.valueOf(funcsarr));
	}
}
